﻿using System;
using System.Collections.Generic;

namespace UpLoadPSDataSystem.Util
{
    public class DataLostAlgorithm
    {
        /// <summary>
        /// 查找缺失的时间点，不包含start和end
        /// </summary>
        /// <param name="source"></param>
        /// <param name="start"></param>
        /// <param name="end"></param>
        /// <param name="dataType"></param>
        /// <returns></returns>

        public static List<DateTime> CheckData(List<DateTime?> source, DateTime start, DateTime end, DataTypeEnum dataType)
        {
            //start = new DateTime(start.Year, start.Month, start.Day, start.Hour, 0, 0);

            //end = new DateTime(end.Year, end.Month, end.Day, start.Hour, 0, 0);

            TimeSpan timeSpan;

            var list = new List<DateTime>();

            switch (dataType)
            {
                //case DataTypeEnum.Minute:
                //    timeSpan = new TimeSpan(0, 0, 10, 0);
                //    for (DateTime item = start; item <= end; item += timeSpan)
                //    {
                //        bool flag = false;
                //        foreach (var exsitItem in source)
                //        {
                //            if (exsitItem != null && exsitItem.Value.Day == item.Day && exsitItem.Value.Hour == item.Hour && exsitItem.Value.Minute / 10 == item.Minute / 10)
                //            {
                //                flag = true;
                //                break;
                //            }
                //        }
                //        if (!flag && item != start && item != end)
                //        {
                //            list.Add(item);
                //        }
                //    }
                //    break;
                case DataTypeEnum.Hour:
                    timeSpan = new TimeSpan(0, 1, 0, 0);

                    for (DateTime item = start; item <= end; item += timeSpan)
                    {
                        bool isExist = false;
                        foreach (var existItem in source)
                        {
                            if (existItem != null && existItem.Value.Year == item.Year && existItem.Value.Month == item.Month && existItem.Value.Day == item.Day && existItem.Value.Hour == item.Hour)
                            {
                                isExist = true;
                                break;
                            }
                        }
                        if (!isExist)// && item != start && item != end)
                        {
                            list.Add(item);
                        }
                    }
                    break;
                case DataTypeEnum.Day:
                    timeSpan = new TimeSpan(1, 0, 0, 0);
                    for (DateTime item = start; item <= end; item += timeSpan)
                    {
                        bool flag = false;
                        foreach (var exsitItem in source)
                        {
                            if (exsitItem != null && exsitItem.Value.Year == item.Year && exsitItem.Value.Month == item.Month && exsitItem.Value.Day == item.Day)
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)// && item != start && item != end)
                        {
                            list.Add(item);
                        }
                    }
                    break;
            }
            return list;
        }

    }

}
